<?php

/**
 * 产品详细信息
 * @copyright   Copyright (c) 2006 - 2010 DZH 友拓软件友拓通
 * @category    统计
 * @package   Action
 * @author     庄敏学
 * @version  2.1,2012-07-22
 */

class StatProductPublicAction extends RelationCommonAction  {

	public function index(){
			$this->display();
	}
	
	/// 产品详细信息(明细)
	public function view() {
		$model			= D($this->getActionName());
		$product_id		= intval($_REQUEST['product_id']);
		
		/// 基本信息
		$basic_info		= $model->getBasicInfo($product_id);
		/// 经营异动信息
		$run_info		= $model->getRunInfo($product_id);	
		///　库存信息	
		$storage_info	= D('StatProduct')->getStorageInfo($product_id);	
		/// 权限处理
		$rights			= array('instock' => 1, 'sale' => 1, 'adjust' => 1 , 
								'sale_price' => 1, 'instock_price' => 1, 'storage' => 1,'inistorage'=>1,'return'=>1,'delivery'=>1);						
		if (C('rights_level') == 3) { /// 普能用户
			$all_rights  = RBAC::getModuleAccessList(USER_ID,'StatProduct');	
			$all_rights	 = array_keys($all_rights['STATPRODUCT']);
			if (!empty($all_rights)) {				
				if (!in_array('PRODUCTINSTOCK',$all_rights)) {	/// 进货数量				
					$rights['instock'] = 0;
				}
				if (!in_array('PRODUCTADJUST', $all_rights)) {  /// 调速数量
					$rights['adjust'] = 0;
				}
				if (!in_array('PRODUCTSALE', $all_rights)) {  /// 销售数量
					$rights['sale'] = 0;
				}
				
				if (!in_array('PRODUCTSTORAGE', $all_rights)) { /// 查看库存
					$rights['storage'] = 0;
				}
				if(!in_array('PRODUCTSTORAGEINI',$all_rights)){
					$rights['inistorage']=0;
				}
				if(!in_array('PRODUCTRETURN',$all_rights)){
					$rights['return']=0;
				}
				if(!in_array('PRODUCTDELIVERY',$all_rights)){
					$rights['delivery']=0;
				}
			} else {
				$rights		= array('instock' => 0, 'sale' => 0, 'adjust' => 0,'sale_price' => 0, 'instock_price' => 0, 'storage' => 0,'inistorage'=>0,'return'=>0,'delivery'=>0);
			}
		}
		$this->assign ("basic_info", $basic_info);
		$this->assign ("run_info", $run_info);
		$this->assign ("storage_info", $storage_info);
		$this->assign ("id", $product_id);
		$this->assign ("rights", $rights);
		$this->display('list');
	}
	
	///查看进货数量
	public function productInstock(){
		$list		=  D('StatProduct')->getDetail();
		$rights		= 1;
		if (C('rights_level') == 3) { // 普能用户
			$all_rights  = RBAC::getModuleAccessList(USER_ID,'StatProduct');
			$all_rights	 = array_keys($all_rights['STATPRODUCT']);				
			if (!in_array('PRODUCTINSTOCKMONEY',$all_rights)) {	// 进货数量				
				$rights = 0;
			}
		}			
		$this->assign('rights',$rights);
		$this->assign('list', $list);
		$this->assign('page', $list['page']);
		$this->display('productDetail');
	}
	///订货未装柜
	public function orderUnload(){
		$this->productInstock();
	}
	///装柜未入库
	public function loadUninstock(){
		$this->productInstock();
	}
	
	/// 产品详细信息(调整)
	public function productAdjust() {
		$source		=  D('StatProduct')->getDetail();
		/// 检查是否有查看金额的权限
		$rights = 1;
		if (C('rights_level') == 3) { /// 普能用户
			$all_rights  = RBAC::getModuleAccessList(USER_ID,'StatProduct');
			$all_rights	 = array_keys($all_rights['STATPRODUCT']);				
			if (!in_array('PRODUCTADJUSTMONEY',$all_rights)) {	/// 进货数量				
				$rights = 0;
			}
		}			
		$this->assign('list', $source);
		$this->assign('page', $source['page']);
		$this->assign('rights', $rights);
		$this->display('productDetail');
	}
	/// 产品详细信息(进货数量报表)
	public function productSale() {
		$source		=  D('StatProduct')->getDetail();	
		/// 检查是否有查看金额的权限
		$rights = 1;
		if (C('rights_level') == 3) { /// 普能用户
			$all_rights  = RBAC::getModuleAccessList(USER_ID,'StatProduct');
			$all_rights	 = array_keys($all_rights['STATPRODUCT']);	
			if (!in_array('PRODUCTSALEMONEY',$all_rights)) {	/// 进货数量				
				$rights = 0;
			}
		}		
		$this->assign('client_currency',count(explode(',',C('client_currency'))));
		$this->assign('list', $source);
		$this->assign('page', $source['page']);
		$this->assign('rights', $rights);
		$this->display('productDetail');
	}
	///产品详细信息 退货数量
	public function productReturn(){
		$this->productSale();
	}
	///期初数量
	public function productStorageIni(){
		$this->productSale();
	}
	///发货数量
	public function productDelivery(){
		$this->productSale();
	}

}